<%@ page pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="path" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>花光马云的钱后台管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="../../css/public.css" media="all" />
	<link rel="stylesheet" href="../../css/my.css" media="all" />
	
</head>
<body class="childrenBody">
<form class="layui-form layui-row layui-col-space10">
	<div class="layui-col-md9 layui-col-xs12">
		<div class="layui-row layui-col-space10">
			<div class="layui-col-md9 layui-col-xs7">
				<div class="layui-form-item magt3">
					<label class="layui-form-label required">商品名称</label>
					<div class="layui-input-block">
						<input type="hidden" name="id" value="${goods.id}">
						<input type="text" name="title" value="${goods.title}" class="layui-input newsName" lay-verify="required" placeholder="请输入商品名称">
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label required">价格</label>
					<div class="layui-input-block">
						<input type="number" name="price" value="${goods.price}" class="layui-input newsName" lay-verify="required" placeholder="请输入商品价格">
					</div>
				</div>	
				
				<div class="layui-form-item">
					<label class="layui-form-label required">商品介绍</label>
					<div class="layui-input-block">
						<textarea name="info" placeholder="请输入商品介绍" lay-verify="required" class="layui-textarea abstract">${goods.info}</textarea>
					</div>
				</div>

			</div>
			<div class="layui-col-md3 layui-col-xs5">
				<div class="layui-upload-list thumbBox mag0 magt4">
					<img class="layui-upload-img thumbImg" src="${goods.imgPath}">
					<input type="hidden" name="imgPath" id="imgPath" value="${goods.imgPath}">
				</div>
			</div>
		</div>
			<div class="layui-col-md3 layui-col-xs12">
		<blockquote class="layui-elem-quote title magt10"><i class="layui-icon">&#xe609;</i> 发布</blockquote>
		<div class="border">
			<div class="layui-form-item">
				<label class="layui-form-label"><i class="layui-icon">&#xe60e;</i> 状　态</label>
				<div class="layui-input-block newsStatus">
					<select name="status" lay-verify="required">
						<option value="0" <c:if test="${goods.status==0}">selected</c:if>>保存草稿</option>
						<option value="1" <c:if test="${goods.status==1}">selected</c:if>>等待审核</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><i class="layui-icon">&#xe609;</i> 发　布</label>
				<div class="layui-input-block">
					<input type="radio" name="release" title="立即发布" lay-skin="primary" lay-filter="release" checked />
					<input type="radio" name="release" title="定时发布" lay-skin="primary" lay-filter="release" />
				</div>
			</div>
			<div class="layui-form-item layui-hide releaseDate">
				<label class="layui-form-label"></label>
				<div class="layui-input-block">
					<input type="text" name="ctime" class="layui-input" id="release" placeholder="请选择日期和时间" readonly />
				</div>
			</div>
			<div class="layui-form-item openness">
				<label class="layui-form-label"><i class="seraph icon-look"></i> 公开度</label>
				<div class="layui-input-block">
					<input type="radio" name="open" value="1" title="开放浏览" lay-skin="primary" <c:if test="${goods.open==1}">checked</c:if> />
					<input type="radio" name="open" value="0" title="私密浏览" lay-skin="primary" <c:if test="${goods.open==0}">checked</c:if> />
				</div>
			</div>
			<div class="layui-form-item newsTop">
				<label class="layui-form-label"><i class="seraph icon-zhiding"></i> 置　顶</label>
				<div class="layui-input-block">
					<input type="checkbox" id="top" name="top" lay-skin="switch" lay-filter="top" lay-text="是|否" <c:if test="${goods.top==1}">checked</c:if> />
				</div>
			</div>			
		</div>
	</div>
	
		
	</div>

	<div class="layui-form-item layui-hide">
	 	<input type="button" lay-submit lay-filter="LAY-form-submit" id="LAY-form-submit" value="确认添加">
	    <input type="button" lay-submit lay-filter="LAY-form-edit" id="LAY-form-edit" value="确认编辑">
	</div>
</form>

<script type="text/javascript" src="${path}/layui/layui.js"></script>
<script type="text/javascript" src="${path}/js/commons.js"></script>
<script>
layui.use(['form','layer','layedit','laydate','upload'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        laypage = layui.laypage,
        upload = layui.upload,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;
	
    //创建一个编辑器
    var editIndex = layedit.build('news_content',{
        height : 335,
        uploadImage : {
            url : '${path}/action/file/upload'
        }
    });

    //上传缩略图
    upload.render({
        elem: '.thumbBox',
        url: '${path}/action/file/upload',
        done: function(res, index, upload){       	
            $('.thumbImg').attr('src', res.data.src);
            $('.thumbBox').css("background","#fff");
            $('#imgPath').val(res.data.src);
        }
    });

    //格式化时间
    function filterTime(val){
        if(val < 10){
            return "0" + val;
        }else{
            return val;
        }
    }
    //定时发布
    var time = new Date();
    var submitTime = time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate())+' '+filterTime(time.getHours())+':'+filterTime(time.getMinutes())+':'+filterTime(time.getSeconds());
    laydate.render({
        elem: '#release',
        type: 'datetime',
        trigger : "click",
        done : function(value, date, endDate){
            submitTime = value;
        }
    });    
    form.on("radio(release)",function(data){
        if(data.elem.title == "定时发布"){
            $(".releaseDate").removeClass("layui-hide");
            $(".releaseDate #release").attr("lay-verify","required");
        }else{
            $(".releaseDate").addClass("layui-hide");
            $(".releaseDate #release").removeAttr("lay-verify");
            submitTime = time.getFullYear()+'-'+(time.getMonth()+1)+'-'+time.getDate()+' '+time.getHours()+':'+time.getMinutes()+':'+time.getSeconds();
        }
    });
    
  	//监听提交
	form.on('submit(LAY-form-submit)', function(data) {
		data.field.content = layedit.getContent(editIndex);
		data.field.top = $('#top').prop('checked')?1:0;		
  		var index = parent.layer.getFrameIndex(window.name); 
  		$$.ajax({
  			url: '${path}/action/goods/save',
  			data: data.field,
  			success: function(json) {
  				parent.layui.table.reload('LAY-table');
  	      		parent.layer.close(index);	
  			}
  		});
	});   

})

</script>
</body>
</html>